package com.kaifamiao.decimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Arithmetic {

    public static void main(String[] args) {

        BigDecimal first = BigDecimal.valueOf( 12345, 3 );
        System.out.println( first );

        BigDecimal second = BigDecimal.valueOf( 314, 2 );
        System.out.println( second );

        // 求和
        BigDecimal result = first.add( second ); // first + second
        System.out.println( result );

        // 求差
        result = first.subtract( second ); // first - second
        System.out.println( result );

        // 求积
        result = first.multiply( second );
        System.out.println( result );

        // 求商
        // result = first.divide( second); // first / second
        result = first.divide( second , RoundingMode.HALF_UP ); // first / second
        System.out.println( result );

    }

}
